#ifndef SCENE_H
#define SCENE_H

#include "coreMesh.h"
//#include "coreController.h"
#include "Instance.h"
#include "framework.h"
#include "textures.h"
#include <iostream> //to output
#include <string>
#include "utils.h"
#include "projectile.h"
#include "camera.h"
#include "shader.h"
#include "clipper.h"
#include "pSystemManager.h"
#include "pSystem.h"
#include "bass.h"
#include <cassert>
#include "rendertotexture.h"

#define LAYERS 3

#define EST_JUEGO 0
#define EST_GANA 1
#define EST_PIERDE 2
#define EST_CARGA 3
#define EST_PAUSA 4

class Scene{

private:
	
	 //std::map<char*, coreController*> loaded_controllers;
	static std::map<std::string, int > loaded_textures;
	static std::vector<Instance*> instances_layer0;
	
	static std::vector<Instance*> instances_layer2;
	

	GLuint * textures_id;
	static Camera * camera; //our global camera
	void UploadVariablesShader(Shader * _shader, coreMesh * _mesh,  Ship * _ship);
	static Scene * scene;

public:
	int estado_juego;
	static std::vector<Instance*> instances_layer1;

	static std::map<std::string, coreMesh*> loaded_meshes;
	static std::vector<Projectile*> projectiles;
	// *********************************
	Vector3 light_position[2];
	Vector3 light_color[2];
	//std::vector<Vector3> light_position;
	//std::vector<Vector3> light_color;
	//Colores;
	Vector3 ambient_factor;
	Vector3 diffuse_factor;
	Vector3 specular_factor;

	//Intensidades
	float ambient_intensity;
	float diffuse_intensity;
	float specular_intensity;

	//Alpha
	float glossiness;
	
	int lastProjectileEmpty;
	double last_time;
	//RendertoTexture
	RenderToTexture * rtt;


	Scene();
	~Scene();
	static void reloadScene();
	static Scene* getScene();
	bool LoadTextures(std::vector<std::string> textures);
	void NewInstance(std::string _meshName, std::string _controllerName, Vector3  _pos, Matrix44 * _model, int _layer);
	void NewShip(std::string _meshName, std::string _controllerName, Vector3  _pos, Matrix44 * _model, std::string _tipo_nave, std::string _shader, std::string _team);
	static coreMesh* LoadCore(std::string _filename);
	bool ActivateTexture(std::string _name);
	std::vector <Instance*>::iterator getInstanceIteratorBegin(int _layer);
	std::vector <Instance*>::iterator getInstanceIteratorEnd(int _layer);
	Instance* getInstance(int _numInstance, int _layer);
	Ship* getShipById(int _id);
	Ship* getShipPlayer();
	int getInstanceSize(int _layer);
	void addProjectile(Vector3 _origen, Vector3 _velocidad, int owner, int tipo);
	void renderSceneLayer(int _layer);
	void renderScene();
	void updateScene(double seconds_elapsed);

	void loadMatrices(const Matrix44& model, const Matrix44& view, const Matrix44& projection);

	void setCamera();
	Camera * getCamera();
	void DrawHUD();
	
	//posicion normalizada de 0 a 1
	void DrawQuad(float _sizex , float _sizey, float _pos_x, float _pos_y, float _pos_z, std::string _texture);
	void DrawQuad2D(float _sizex , float _sizey, float _pos_x, float _pos_y);
	Vector3 get2DPoint(Vector3 & worldPoint);
};
#endif
